<?php

namespace App\HttpController;


use App\Common\Log;
use App\Common\SysContext;
use App\Common\Web\TempView;
use App\X\EHelper;
use EasySwoole\Http\AbstractInterface\Controller;


class index extends Controller
{
    function index()
    {
        if (!EHelper::funcIsDev())
        {
            $this->response()->redirect('http://admin.siyoumi.com/');
        }
        else
        {
            $this->writeJson();
        }
    }


    protected function onException(\Throwable $throwable): void
    {
        $app = new TempView('/error/500.html');

        $errmsg = "{$throwable->getMessage()} at file:{$throwable->getFile()} line:{$throwable->getLine()}";
        Log::funcLogErr(__METHOD__, $errmsg);

        $app->funcSetReplace([
            '{getMessage}' => $throwable->getMessage(),
            '{getTraceAsString}' => $throwable->getTraceAsString(),
            '{errmsg}' => $errmsg,
        ]);

        $r = $app->funcPageContent();

        $this->response()->write($r->getData('page_content'));
    }
}